<template>
  <div class="search-home">
    <!-- 动态背景 -->
    <div class="bg-layer">
      <div class="bg-gradient"></div>
      <div class="bg-orbs">
        <div class="orb orb-1"></div>
        <div class="orb orb-2"></div>
        <div class="orb orb-3"></div>
      </div>
    </div>

    <!-- 主内容 -->
    <main class="main-content">
      <!-- Logo 和标题 -->
      <div class="brand-section">
        <div class="logo">
          <svg viewBox="0 0 64 64" fill="none">
            <defs>
              <linearGradient id="water-grad" x1="0%" y1="0%" x2="100%" y2="100%">
                <stop offset="0%" stop-color="#00d4ff"/>
                <stop offset="100%" stop-color="#0066ff"/>
              </linearGradient>
            </defs>
            <path d="M32 8c0 0-18 15-18 30a18 18 0 0 0 36 0c0-15-18-30-18-30z" fill="url(#water-grad)"/>
            <path d="M24 36c0 4.4 3.6 8 8 8s8-3.6 8-8" stroke="white" stroke-width="3" stroke-linecap="round" fill="none"/>
          </svg>
        </div>
        <h1 class="title">知汛助手</h1>
      </div>

      <!-- 搜索框 -->
      <div class="search-section">
        <SearchBox 
          ref="searchBoxRef"
          @select="handleSelect"
          @search="handleSearch"
          :placeholder="'输入测站名称、编码、别名进行搜索...'"
        />
      </div>

      <!-- 热门搜索 -->
      <div class="hot-section">
        <span class="hot-label">热门搜索</span>
        <div class="hot-tags">
          <button 
            v-for="(tag, index) in hotTags" 
            :key="tag.name"
            class="hot-tag"
            @click="handleHotClick(tag)"
          >
            <span v-if="index < 3" class="hot-rank">{{ index + 1 }}</span>
            {{ tag.name }}
          </button>
        </div>
      </div>
    </main>

    <!-- 底部 -->
    <footer class="footer">
      <span>智水慧成 © 2025</span>
    </footer>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import SearchBox from './SearchBox.vue'

const searchBoxRef = ref(null)

// 热门搜索（TODO: 从 API 获取）
const hotTags = ref([
  { name: '碧流河水库', code: '21401050' },
  { name: '松花江', code: '21100100' },
  { name: '辽河', code: '21200100' },
  { name: '大伙房水库', code: '21401100' },
  { name: '观音阁', code: '21300200' },
  { name: '浑河', code: '21201000' },
])

// 选择测站后跳转到详情页
function handleSelect(item) {
  navigateToDetail(item)
}

// 搜索后跳转到详情页（带搜索词）
function handleSearch(query) {
  // 如果只是搜索文本，跳转到结果页
  uni.navigateTo({
    url: `/pages/station/portal?q=${encodeURIComponent(query)}`
  })
}

// 点击热门标签
function handleHotClick(tag) {
  navigateToDetail({ code: tag.code, name: tag.name })
}

// 跳转到详情页
function navigateToDetail(station) {
  const params = new URLSearchParams()
  if (station.code) params.set('stcd', station.code)
  if (station.name) params.set('name', station.name)
  if (station.type) params.set('type', station.type)
  
  uni.navigateTo({
    url: `/pages/station/portal?${params.toString()}`
  })
}

onMounted(() => {
  setTimeout(() => {
    searchBoxRef.value?.focus()
  }, 300)
})
</script>

<style scoped>
.search-home {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  font-family: 'PingFang SC', 'Microsoft YaHei', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* 背景 */
.bg-layer {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 0;
}

.bg-gradient {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
}

.bg-orbs {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.4;
}

.orb-1 {
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, #0066ff 0%, transparent 70%);
  top: -200px;
  left: -200px;
  animation: float 20s ease-in-out infinite;
}

.orb-2 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, #00d4ff 0%, transparent 70%);
  bottom: -100px;
  right: -100px;
  animation: float 15s ease-in-out infinite reverse;
}

.orb-3 {
  width: 300px;
  height: 300px;
  background: radial-gradient(circle, #6366f1 0%, transparent 70%);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation: pulse 10s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(30px, 30px); }
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: translate(-50%, -50%) scale(1); }
  50% { opacity: 0.5; transform: translate(-50%, -50%) scale(1.1); }
}

/* 主内容 */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  position: relative;
  z-index: 1;
}

/* 品牌区 */
.brand-section {
  text-align: center;
  margin-bottom: 48px;
}

.logo {
  width: 96px;
  height: 96px;
  margin: 0 auto 24px;
  animation: logo-float 4s ease-in-out infinite;
}

@keyframes logo-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.logo svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 8px 32px rgba(0, 212, 255, 0.3));
}

.title {
  font-size: 42px;
  font-weight: 700;
  background: linear-gradient(135deg, #ffffff 0%, #94a3b8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 0 0 12px;
  letter-spacing: 2px;
}

.subtitle {
  font-size: 16px;
  color: #64748b;
  margin: 0;
  letter-spacing: 4px;
}

/* 搜索区 */
.search-section {
  width: 100%;
  max-width: 640px;
  margin-bottom: 32px;
}

/* 热门搜索 */
.hot-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.hot-label {
  font-size: 13px;
  color: #64748b;
}

.hot-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.hot-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  color: #cbd5e1;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.hot-tag:hover {
  background: rgba(0, 212, 255, 0.15);
  border-color: rgba(0, 212, 255, 0.3);
  color: #00d4ff;
  transform: translateY(-2px);
}

.hot-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  background: linear-gradient(135deg, #f97316 0%, #ef4444 100%);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  color: white;
}

/* 底部 */
.footer {
  padding: 24px;
  text-align: center;
  font-size: 13px;
  color: #475569;
  position: relative;
  z-index: 1;
}

/* 响应式 */
@media (max-width: 768px) {
  .title {
    font-size: 32px;
  }
  
  .logo {
    width: 72px;
    height: 72px;
  }
  
  .subtitle {
    font-size: 14px;
    letter-spacing: 2px;
  }
  
  .main-content {
    padding: 32px 16px;
  }
}
</style>

